--
-- project.json:
-- {
--  "common":[
--   ],
--  "game": [
--    "Basic/Basic.lua",
--    "Demo/Keyboard.lua"
--  ],
--  "ui": [
--    "Basic/Basic.lua",
--    "Basic/Song_1.lua",
--    "Basic/Song_2.lua",
--    "Basic/Song_3.lua",
--    "Basic/Song_4.lua",
--    "Basic/Song_5.lua",
--    "Basic/Song_6.lua",
--    "Demo/Keyboard.lua"
--  ]
-- }


if UI then

    -- Frame.mainLayer:add(Dialog((UI.ScreenSize().width - 800)/2,UI.ScreenSize().height * 0.8,800,100,"提示","+M"));

    --实例化一个按键监听器
    local keyboard = Keyboard();
    --启用按键监听器
    keyboard:enable();


    --绑定一个组合键
    --按键名大写表示按下事件，小写表示抬起事件
    --按键名前加'_'符号表示持续按下
    keyboard:bind("_SHIFT+M",function ()
        Toast:makeText("按住SHIFT键，然后按下M键");
    end);

    keyboard:bind("_SHIFT+N",function ()
        Toast:makeText("按住SHIFT键，然后按下N键");
    end);

    keyboard:bind("SHIFT+N",function ()
        Toast:makeText("依次按下SHIFT键,N键");
    end);
    
    keyboard:bind("SHIFT+N+K",function ()
        Toast:makeText("依次按下SHIFT键,N键,K键");
    end);

    keyboard:bind("_B+n",function ()
        Toast:makeText("按住B建然后抬起N键");
    end);

    ----------------

    keyboard:bind("MOUSE1+mouse1",function ()
        Toast:makeText("鼠标左键按下后抬起");
    end);

    keyboard:bind("_MOUSE1+space",function ()
        Toast:makeText("按住鼠标左键然后抬起空格");
    end);

    keyboard:bind("_MOUSE1+SPACE",function ()
        Toast:makeText("按住鼠标左键然后按下空格");
    end);

    local mn = keyboard:bind("_MOUSE1+num1",function ()
        Toast:makeText("按住鼠标左键然后抬起数字1键");
    end);

    --解除按键绑定
    keyboard:unbind(mn);
    
    --按O键打开菜单
    MainMenu.root:add({
        "关闭按键监听",function(item)
            if keyboard.isEnable == true then
                item.name = "开启按键监听";
                keyboard:disable();
            else
                item.name = "关闭按键监听";
                keyboard:enable();
            end
        end
    },2);

end